package Week7.J0528;

// 双数组 + 动态规划

import java.io.*;
import java.util.StringTokenizer;

public class 天使果冻_xv {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();

    public static int n;
    public static int[][] arr;

    public static void main(String[] args) throws IOException {
        n = in.nextInt();
        arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                arr[i][j] = in.nextInt();
            }
        }

        int q = in.nextInt();
        int row = 0, col = 0;

        while (q-- != 0) {
            int x = in.nextInt();
            if (x == 1) {
                row++;
                col++;
            } else row++;
        }

        row %= 2;
        col %= 2;
        if (row != 0) setRow();
        if (col != 0) setCol();

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                out.print(arr[i][j] + " ");
            }
            out.println();
        }
        out.close();
    }

    private static void setRow() {
        for (int i = 0; i < n / 2; i++) {
            for (int j = 0; j < n; j++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[n - 1 - i][j];
                arr[n - 1 - i][j] = tmp;
            }
        }
    }

    private static void setCol() {
        for (int j = 0; j < n / 2; j++) {
            for (int i = 0; i < n; i++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[i][n - 1 - j];
                arr[i][n - 1 - j] = tmp;
            }
        }
    }

}


class Read {//自定义快读读入
    //字符串裁剪
    StringTokenizer st = new StringTokenizer("");

    //1.字节流System.in->字符流InputStreamReader
    //2.带内存缓冲区的字符流BufferedReader
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));


    String next() throws IOException {
        //为什么要while循环，因为可能读取的数据不止一行，有多行就需要多次取
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());//先拿一行的数据
        }
        return st.nextToken();//对这一行的数据进行裁剪，拿到第一个数据
    }

    String nextLine() throws IOException {
        return bf.readLine();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}